package alvarodelrosal.chat.server.modelo.chataction;

import alvarodelrosal.chat.server.infraestructura.ChatLiveConversations;
import alvarodelrosal.chat.server.infraestructura.ChatPersistenceManager;
import alvarodelrosal.chat.server.modelo.ChatConnection;
import java.util.List;

public class ChatByeChat implements ChatAction {

    @Override
    public String getName() {
        return "ByeChat";
    }

    @Override
    public boolean needsAdminPrivileges() {
        return false;
    }

    @Override
    public boolean needsLogin() {
        return true;
    }

    @Override
    public String doAction(ChatConnection connection, List<String> parameters) {
        ChatPersistenceManager.getPersistenceManager().save(ChatLiveConversations.getConversation(Integer.parseInt(parameters.get(0))));
        ChatLiveConversations.removeConnectionFromConversation(connection, Integer.parseInt(parameters.get(0)));
        return "";
    }

}
